<!doctype html>
<!--[if lt IE 7 ]> <html lang="ja" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="ja" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="ja" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="ja" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="ja" class="no-js"> <!--<![endif]-->
<head>
	<meta charset="UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

	<title>jQuery.uniquArray() プラグインをテスト</title>
	<meta name="description" content="" />
	<meta name="author" content="Y.Nishimura@Office L / nishimuray@gmail.com" />

	<meta name="viewport" content="width=device-width, initial-scale=1.0" />

	<link rel="shortcut icon" href="/favicon.ico" />
	<link rel="apple-touch-icon" href="/apple-touch-icon.png" />

	<link rel="stylesheet" href="css/test.style.css?v=1" />

	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
	<script type="text/javascript" src="js/modernizr.js"></script>
	<script>!window.jQuery && document.write('<script src="js/jquery-1.6.1.js"><\/script>')</script>
	<script type="text/javascript" src="js/test.script.js"></script>
</head>
<body>

<div id="log">出現順にコンソールログ参照</div>



<script type="text/javascript">
<!-- 

/*
jquery-uniqueArray.js
By: William Skidmore - www.wskidmore.com

Purpose: Remove duplicates elements in an array
               [1,1,2,2,3,3] -> [1,2,3]

Installation: Include jquery first, then this js file.

Usage:
	var myArray = ["Bob","Bob","Mary","Susan","Susan"];
	myArray = $.uniqueArray(myArray);
	document.write(myArray);
	
	outputs -- Bob, Mary, Susan
	
License: Released under MIT License:
Copyright (c) 2010 William Skidmore

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
*/
jQuery.extend({
	uniqueArray: function(array){
		if ($.isArray(array)){
			var dupes = {}; var len, i;
			for (i=0,len=array.length;i < len;i++){	// 注：エディタがHTMLだと勘違いするので間にスペースいれました
				var test = array[i].toString();
				if (dupes[test]) { array.splice(i,1); len--; i--; } else { dupes[test] = true; }
			}
		} else {
			if (window.console) console.log('Not passing an array to uniqueArray, returning whatever you sent it - not filtered!');
			return(array);	// 注：ロジック的なことを考えたらこの return 文は不要な気がします
		}
		return(array);
	}
});

$(function() {

	console.info("普通の配列");
	var arr1 = [1,2,1,2,3,1,2,3,4,5,6];
	console.log($.uniqueArray(arr1));
	console.log(arr1);
	console.warn("元のarr1の内容が変わってしまう（＝破壊的ということ）");

	console.info("あまりよろしくない連想配列");
	var arr2 = {"1":"s1",0:"n0",1:"n1","0":"s0"};
	console.log(arr2);
	console.log($.uniqueArray(arr2));
	console.warn("isArrayがfalseなので処理されない");

	console.info("array in array");
	var arr3 = [1,2,{3:"s3",4:"s4"},2,{3:"s3",4:"s4"},5,{3:"s3",5:"s5"}];
	console.log($.uniqueArray(arr3));
	console.warn("配列はユニークになり、オブジェクトは最初に処理されるオブジェクトにまとめられる");

});
// -->
</script>

</body>
</html>
